package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;

public class HJ14_数组的中心位置 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/14.txt"));
        int[] nums = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int len = nums.length;
        if (len == 1) {
            System.out.println(0); //根据端点处左侧积为1，右侧积为1。
            return;
        }
        BigInteger[] pre = new BigInteger[len]; //考虑大数，用 BigInteger
        pre[0] = BigInteger.valueOf(nums[0]);
        for (int i = 1; i < len; i++) {
            pre[i] = pre[i - 1].multiply(BigInteger.valueOf(nums[i]));
        }
        for (int i = 1; i < len - 1; i++) {
            BigInteger left = pre[i - 1];
            BigInteger right = pre[len - 1].divide(pre[i]);
            if (Objects.equals(left, right)) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
}
